package com.ricky.spring.demo.service.impl;

import com.ricky.spring.demo.service.MessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.concurrent.Future;

/**
 * @author leiruiqi {@literal <leiruiqi@baijiahulian.com>}
 **/
@Slf4j
@Service
public class MessageServiceImpl implements MessageService {

    @Async("taskExecutor")
    @Override
    public Future<String> sendMsg(String clientName, String msg) {
        String str = String.format("send message to user:{%s}, msg:{%s}",clientName,msg);
        try {
            Thread.sleep(5L);
            return new AsyncResult<String>(str);
        } catch (InterruptedException e) {
            e.printStackTrace();
            return new AsyncResult<String>("");
        }
    }
}
